package com.es.listener;

import org.apache.rocketmq.common.message.MessageExt;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import com.es.rocket.RocketmqEvent;

@Component
public class ConsumerEvnListener implements ApplicationListener<RocketmqEvent>{

	@Override
	//@EventListener(condition="event.msgs[0].topic=='topicTest' && #event.msgs[0].tags=='tagA'")
	public void onApplicationEvent(RocketmqEvent event) {
		try {
			if (event.getMsgs() != null && !event.getMsgs().isEmpty()) {
				for (MessageExt msg : event.getMsgs()) {
					String content = event.getMsg(msg.getBody());
					System.out.println(content);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
